package cn.jlearn.proxy.web.config;

import cn.dev33.satoken.interceptor.SaRouteInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.Collections;

/**
 * WebMVC相关配置
 *
 * @author qianyingchao
 * @version 1.0
 * @date 2021/1/13 11:07 上午
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SaRouteInterceptor((request, response, handler) ->
                SaRouter.match(Collections.singletonList("/admin/**"),
                        Arrays.asList(
                                "/admin/login.html",
                                "/admin/login/action",
                                "/admin/register.html",
                                "/admin/register/action"
                        ),
                        StpUtil::checkLogin))
        ).addPathPatterns("/**");
    }

}